Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YAML] Fix simple YAML mappings type hinting #31427

Merged
merged 4 commits into from
May 29, 2024

Conversation

Polber
Copy link
Contributor

@Polber Polber commented May 28, 2024

There have been type inferencing issues with Beam YAML MapToFields where the type(s) from the upstream pcollection are dropped when the beam.Select is used on unmapped fields in the MapToFields expansion (i.e. when using append: true, the unmapped fields are mapped to AnyType).

The fix is to register type hints for the implicitly appended fields.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@Polber
Copy link
Contributor Author

Polber commented May 28, 2024

R: @robertwb

Copy link
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

# Extract original type from upstream pcoll when doing simple mappings
if input_schema is None:
input_schema = {}
original_type = input_schema.get(transform_name, None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite understanding why you want to use transform_name as a key in the input schema here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no good reason, I think that was the result of an earlier null issue that no longer applies. Removed a couple lines related to obsolete cases

Signed-off-by: Jeffrey Kinard <[email protected]>
@Polber Polber requested a review from robertwb May 28, 2024 22:11
Copy link
Contributor

@robertwb robertwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to add a test if it's not that hard.

@Polber
Copy link
Contributor Author

Polber commented May 28, 2024

It'd be good to add a test if it's not that hard.

@robertwb
Added a test.

Interestingly, if I remove the following from the test, it correctly inferences the types...

elements.element_type = schemas.named_tuple_from_schema(
    schema_pb2.Schema(
        fields=[
            schemas.schema_field('label', str),
            schemas.schema_field('conductor', int),
            schemas.schema_field('rank', int)
        ]))

i.e. exactly what is done in the ReadFromPubSub which was the IO used in the test case that initially surfaced the error

output.element_type = schemas.named_tuple_from_schema(
schema_pb2.Schema(fields=list(payload_schema.fields) + extra_fields))

Signed-off-by: Jeffrey Kinard <[email protected]>
@Polber Polber force-pushed the jkinard/fix-yaml-mapping branch from aa7a81b to 122b032 Compare May 28, 2024 23:50
Signed-off-by: Jeffrey Kinard <[email protected]>
@Polber
Copy link
Contributor Author

Polber commented May 29, 2024

Fixes #31434

@robertwb robertwb merged commit b1a6eb0 into apache:master May 29, 2024
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants